//
//  JMMeScoreView.m
//  NewiOSProject
//
//  Created by li on 2023/9/26.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMMeScoreView.h"
#import "LayoutView.h"

#import "JMPickerSelectionView.h"
#import "JMPickerSelectionModel.h"
#import "PaddingView.h"
#import "LayoutScrollView.h"
#import "CustomStackView.h"

@interface JMMeScoreView ()

@property(nonatomic ,strong) CAGradientLayer *gl;
@end

@implementation JMMeScoreView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
        
        self.backgroundColor = Hex_Str_COLOR(@"#F6F9FE");
//        [self configureGradientLayer];
//        [self.layer insertSublayer:self.gl atIndex:0];
        self.cornerRadius = 4;
    }
    return self;
}

- (void)setupView {
    
    CustomStackView *rootStack = [CustomStackView init:(UILayoutConstraintAxisVertical)];
    
    rootStack.translatesAutoresizingMaskIntoConstraints = NO;
    rootStack.spacing = 7;
    [self addSubview:rootStack];
    [NSLayoutConstraint activateConstraints:@[
        [rootStack.topAnchor constraintEqualToAnchor:self.topAnchor constant:20],
        [rootStack.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:20],
        [rootStack.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-20],
        [rootStack.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-20],
    ]];
    
    CustomStackView *topStack = [CustomStackView init:(UILayoutConstraintAxisHorizontal)];
    topStack.spacing = 6;
    topStack.alignment = UIStackViewAlignmentCenter;
    [rootStack addArrangedSubview:topStack];
    
    UILabel *titleLab = [UILabel new];
    self.titleLab = titleLab;
    titleLab.textColor = [UIColor colorWithHexString:@"#0F1511"];
    titleLab.font = [UIFont systemFontOfSize:14 weight:(UIFontWeightMedium)];
    [topStack addArrangedSubview:titleLab];
    
    UIButton *topalert = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.topaAlert = topalert;
    [topalert setImage:[UIImage imageNamed:@"ICON／bagnz"] forState:(UIControlStateNormal)];
    [topalert addTarget:self action:@selector(showAlert:) forControlEvents:(UIControlEventTouchUpInside)];
    [topStack addArrangedSubview: [PaddingView initWithContentView:topalert edgeInsets:(UIEdgeInsetsMake(0, 6, 0, 0))]];
    topalert.superview.hidden = YES;
    
    
    UIView *spacer1 = [UIView new];
    spacer1.backgroundColor = [UIColor clearColor];
    [topStack addArrangedSubview: spacer1];
    
    
    
    
    UILabel *scoreLab = [UILabel new];
    self.scoreLab = scoreLab;
    scoreLab.textColor = [UIColor colorWithHexString:@"#1F1F1F"];
    scoreLab.font = [UIFont systemFontOfSize:22 weight:(UIFontWeightBold)];
    scoreLab.textColor = Hex_Str_COLOR(@"#3C57F8");
    [topStack addArrangedSubview:scoreLab];
    
    UIImageView *moreImageView = [UIImageView new];
    moreImageView.image = [UIImage imageNamed:@"more_right_2"];
    moreImageView.translatesAutoresizingMaskIntoConstraints = NO;
    [moreImageView.widthAnchor constraintEqualToConstant:7].active = YES;
    self.moreImageView = moreImageView;
    [topStack addArrangedSubview:moreImageView];
    
    UIButton *obenBtn = [UIButton new];
    [obenBtn setTitle:@"Obtener" forState:(UIControlStateNormal)];
    obenBtn.translatesAutoresizingMaskIntoConstraints = NO;
    obenBtn.backgroundColor = Hex_Str_COLOR(@"#3C57F8");
    obenBtn.cornerRadius = 17;
    [obenBtn setTitleColor:Hex_Str_COLOR(@"#ffffff") forState:(UIControlStateNormal)];
    obenBtn.titleLabel.font = Font(12);
    [obenBtn.widthAnchor constraintEqualToConstant:120].active = YES;
    [obenBtn.heightAnchor constraintEqualToConstant:34].active = YES;
    [topStack addArrangedSubview:obenBtn];
    
    self.obenBtn = obenBtn;
    self.obenBtn.hidden = YES;
    
    
    
    CustomStackView *bottomStack = [CustomStackView init:(UILayoutConstraintAxisHorizontal)];
    self.dateStack = bottomStack;
    bottomStack.alignment = UIStackViewAlignmentCenter;
    bottomStack.spacing = 0;
    [rootStack addArrangedSubview:bottomStack];
    
    
    UILabel *dateTitleLab = [UILabel new];
    
    dateTitleLab.textColor = [UIColor colorWithHexString:@"#959892"];
    dateTitleLab.font = [UIFont systemFontOfSize:12];
    dateTitleLab.text = @"Fecha de generación del informe: ";
    [bottomStack addArrangedSubview:dateTitleLab];
    
    UILabel *dateLab = [UILabel new];
    self.dateLab = dateLab;
    dateLab.textColor = [UIColor colorWithHexString:@"#222222"];
    dateLab.font = [UIFont systemFontOfSize:12];
    [bottomStack addArrangedSubview:dateLab];
    
    UIButton *alert = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.alert = alert;
    [alert setImage:[UIImage imageNamed:@"ICON／bagnz"] forState:(UIControlStateNormal)];
    [alert addTarget:self action:@selector(showAlert:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [bottomStack addArrangedSubview: [PaddingView initWithContentView:alert edgeInsets:(UIEdgeInsetsMake(0, 6, 0, 0))]];
    alert.superview.hidden = YES;
    bottomStack.hidden = YES;
    
    [bottomStack addArrangedSubview: [UIView new]];

    
    [rootStack setCustomSpacing:0 afterView:bottomStack];

    

    
    UILabel *errorLab = [UILabel new];
    self.errorLab = errorLab;
    self.errorLab.textAlignment = 2;
    errorLab.numberOfLines = 0;
    errorLab.hidden = YES;
    errorLab.textColor = [UIColor colorWithHexString:@"#FF5252"];
    errorLab.font = [UIFont systemFontOfSize:9];
    [rootStack addArrangedSubview:errorLab];
    
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
//    self.gl.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
//    self.layer.shadowColor = [UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:0.1900].CGColor;
//    self.layer.shadowOffset = CGSizeMake(0,7);
//    self.layer.shadowOpacity = 1;

//    self.layer.cornerRadius = 8;
//    self.layer.masksToBounds = YES;
}

- (void)configureGradientLayer {
    CAGradientLayer *gl = [CAGradientLayer layer];
    self.gl = gl;
    gl.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    gl.startPoint = CGPointMake(0.5, -0.09);
    gl.endPoint = CGPointMake(0.5, 0.5);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    self.layer.cornerRadius = 8;
    self.layer.shadowColor = [UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:0.1900].CGColor;
    self.layer.shadowOffset = CGSizeMake(0,7);
    self.layer.shadowOpacity = 1;
    self.layer.shadowRadius = 20;
    self.layer.masksToBounds = YES;
}

- (void)showAlert:(UIButton *)sender {
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
